﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using QuTouTiaoAssist.Util;

namespace QuTouTiaoAssist
{
    public partial class FrmExchangeRecord : FrmListViewBase
    {
        public FrmExchangeRecord()
        {
            InitializeComponent();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            if (!base.CheckLogin())
                return;

            base.ClearListView(this.listView1);
            new Thread(() =>
            {
                try
                {
                    var result = QttHelper.GetExchangeRecords(base.MemeberToken);
                    if (result.Code == 0)
                    {
                        for (int i = 0; i < result.Data.Count; i++)
                        {
                            base.AppendListViewItem(this.listView1, new object[]
                            {
                                i+1,
                                result.Data[i].ItemName,
                                result.Data[i].CreateTime,
                                result.Data[i].StatusMsg
                            }); 
                        }
                    }
                    else
                    {
                        throw new Exception(result.Message);
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowInfo("查询失败，" + ex.Message);
                }
            }){IsBackground = true}.Start();
        }
    }
}
